import { Controller, Post, Body, UseGuards, Req, Put, Delete, Param } from '@nestjs/common';
import { CreateFriendshipsDto } from './dtos/create-friendships.dto'
import { UpdateFriendshipsDto } from './dtos/update-friendships.dto'
import { ValidationPipe } from '../../pipes/validate.pipe'
import { FriendshipsService } from './friendships.service'
import { AuthGuard } from '../../guard/auth.guard'

@Controller('friendships')
export class FriendshipsController {
    constructor(
        private readonly friendshipsService: FriendshipsService
    ) { }

    @Post()
    @UseGuards(AuthGuard)
    // 添加好友
    postFriendship(@Req() req, @Body(new ValidationPipe) createFriendshipsDto: CreateFriendshipsDto) {
        return this.friendshipsService.createFriendship(createFriendshipsDto, req.userId)
    }

    @Put()
    @UseGuards(AuthGuard)
    putFriendship(@Req() req, @Body(new ValidationPipe) updateFriendshipsDto: UpdateFriendshipsDto) {
        return this.friendshipsService.updateFriendship(updateFriendshipsDto, req.userId)
    }

    @Delete('/:id')
    @UseGuards(AuthGuard)
    deleteFriendship(@Req() req, @Param('id') friend_id: string) {
        return this.friendshipsService.deleteFriendship(friend_id, req.userId)
    }

}
